package utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class FileUtils {
	
	public static String readFile(final String path){
		
		String returnContent = "";
		
		try{
			
			FileInputStream fstream = new FileInputStream(path);
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
			
			while ((strLine = br.readLine()) != null)   {
				returnContent += strLine;
			}
			
			in.close();
			
		}catch (Exception e){
			System.err.println("Error: " + e.getMessage());
		}
		
		return returnContent;
	}

	public static void writeInFile(final String path, final String toSave) {
		try{ 
			FileWriter fstream = new FileWriter(path);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(toSave);
			out.close();
		}catch (Exception e){
			System.err.println("Error: " + e.getMessage());
		}
	}
}
